[google_maps_flutter] Add onPointOfInterestTap callback#11872
Conversation
bd93078 to
336fb13
Compare
Expose a place-ID-only POI tap stream across the federated plugin stack (Android, iOS, web) so apps can react when users tap built-in map POIs. Fixes flutter/flutter#60695
336fb13 to
e125948
Compare
There was a problem hiding this comment.
Code Review
This pull request adds support for tapping points of interest (POIs) on the map across Android, iOS, and Web platforms in the google_maps_flutter plugin. It introduces the PointOfInterestId type and PointOfInterestTapEvent in the platform interface, exposes the onPointOfInterestTap callback on the GoogleMap widget, and implements the platform-specific event handling and Pigeon messaging. The review feedback suggests adding a defensive null check for the PointOfInterest parameter in the Android onPoiClick handler to prevent a potential NullPointerException.
| public void onPoiClick(PointOfInterest pointOfInterest) { | ||
| if (pointOfInterest.placeId != null) { | ||
| flutterApi.onPointOfInterestTap( | ||
| pointOfInterest.placeId, (Result<Unit> result) -> Unit.INSTANCE); | ||
| } | ||
| } |
There was a problem hiding this comment.
Defensively checking pointOfInterest for null before accessing its properties is a good practice to prevent potential NullPointerExceptions, especially since the parameter is not annotated with @NonNull.
| public void onPoiClick(PointOfInterest pointOfInterest) { | |
| if (pointOfInterest.placeId != null) { | |
| flutterApi.onPointOfInterestTap( | |
| pointOfInterest.placeId, (Result<Unit> result) -> Unit.INSTANCE); | |
| } | |
| } | |
| public void onPoiClick(PointOfInterest pointOfInterest) { | |
| if (pointOfInterest != null && pointOfInterest.placeId != null) { | |
| flutterApi.onPointOfInterestTap( | |
| pointOfInterest.placeId, (Result<Unit> result) -> Unit.INSTANCE); | |
| } | |
| } |
There was a problem hiding this comment.
The placeId null guard is the important part, and it’s already there. The Maps SDK only calls onPoiClick with a non-null PointOfInterest when a POI is tapped, and the other click handlers in this class don’t null-check their parameters either. We already have a test for the realistic case (placeId == null), which matches iOS. An extra pointOfInterest != null check would be harmless but unnecessary.
Adds
GoogleMap.onPointOfInterestTap, a callback that fires when the user taps a built-in map point of interest. The callback receives aPointOfInterestIdcontaining the place ID only, matching maintainer feedback on #4052 and #10963.The change is wired through the federated plugin stack: platform_interface (type + event stream), Android (
OnPoiClickListener), iOS including sdk9/sdk10/shared (didTapPOIWithPlaceID), web (IconMouseEvent.placeIdon map click), and the app-facinggoogle_maps_flutterpackage. Tests cover Dart unit tests, Android Robolectric, iOS native, and web integration tests in the web example.Fixes flutter/flutter#60695
Pre-Review Checklist
[shared_preferences]///).Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2